/**
 * HT1621 空调液晶屏驱动
 * Copyright (c) 2021 深圳市智辰科技有限公司
 * All rights reserved.
 */

#ifndef _LCD_AC_H_
#define _LCD_AC_H_

#include <stdint.h>
#include "ht1621.h"


#pragma pack(push, 1)

// 空调面板显存结构
// 参见空调显示屏工程图纸
typedef union {
	uint8_t bytes[9];
	struct {
		uint8_t S1:1;
		uint8_t F1:1;
		uint8_t F2:1;
		uint8_t F3:1;
		uint8_t _res1:4;
		
		uint8_t N1A:1;
		uint8_t N1F:1;
		uint8_t N1G:1;
		uint8_t N1E:1;
		uint8_t _res2:4;
		
		uint8_t M1:1;
		uint8_t N1B:1;
		uint8_t N1C:1;
		uint8_t N1D:1;
		uint8_t _res3:4;
		
		uint8_t N2A:1;
		uint8_t N2F:1;
		uint8_t N2G:1;
		uint8_t N2E:1;
		uint8_t _res4:4;
		
		uint8_t M2:1;
		uint8_t N2B:1;
		uint8_t N2C:1;
		uint8_t N2D:1;
		uint8_t _res5:4;
		
		uint8_t N4A:1;
		uint8_t N4F:1;
		uint8_t N4G:1;
		uint8_t N4E:1;
		uint8_t _res6:4;
		
		uint8_t DP1:1;
		uint8_t N4B:1;
		uint8_t N4C:1;
		uint8_t N4D:1;
		uint8_t _res7:4;
		
		uint8_t N5A:1;
		uint8_t N5F:1;
		uint8_t N5G:1;
		uint8_t N5E:1;
		uint8_t _res8:4;
		
		uint8_t M3:1;
		uint8_t N5B:1;
		uint8_t N5C:1;
		uint8_t N5D:1;
		uint8_t _res9:4;
	} st;
} lcd_ac_ram_t;

#pragma pack(pop)

// 8段数码可显示字符定义
typedef enum {
	LCD_8SEG_CHAR_0,
	LCD_8SEG_CHAR_1,
	LCD_8SEG_CHAR_2,
	LCD_8SEG_CHAR_3,
	LCD_8SEG_CHAR_4,
	LCD_8SEG_CHAR_5,
	LCD_8SEG_CHAR_6,
	LCD_8SEG_CHAR_7,
	LCD_8SEG_CHAR_8,
	LCD_8SEG_CHAR_9,
	LCD_8SEG_CHAR_A, // A
	LCD_8SEG_CHAR_b, // b
	LCD_8SEG_CHAR_C, // C
	LCD_8SEG_CHAR_c, // c
	LCD_8SEG_CHAR_d, // d
	LCD_8SEG_CHAR_E, // E
	LCD_8SEG_CHAR_F, // F
	LCD_8SEG_CHAR_G, // G
	LCD_8SEG_CHAR_H, // H
	LCD_8SEG_CHAR_h, // h
	LCD_8SEG_CHAR_J, // J
	LCD_8SEG_CHAR_L, // L
	LCD_8SEG_CHAR_n, // n
	LCD_8SEG_CHAR_o, // o
	LCD_8SEG_CHAR_p, // p
	LCD_8SEG_CHAR_q, // q
	LCD_8SEG_CHAR_r, // r
	LCD_8SEG_CHAR_t, // t
	LCD_8SEG_CHAR_U, // U
	LCD_8SEG_CHAR_u, // u
	LCD_8SEG_CHAR_y, // y
	LCD_8SEG_CHAR_MINUS, // -
	LCD_8SEG_CHAR_UNDERLINE, // _
	LCD_8SEG_CHAR_MAX,
} lcd_ac_8seg_char_t;

// 模式
typedef enum {
	LCD_MODE_COOL,
	LCD_MODE_WARM,
	LCD_MODE_WIND,
} lcd_ac_mode_t;

// 风速
typedef enum {
	LCD_FAN_SPEED_LOW,
	LCD_FAN_SPEED_MEDIUM,
	LCD_FAN_SPEED_HIGH,
} lcd_ac_fan_speed_t;

// LCD 初始化
void lcd_ac_init(const driver_ht1621_t* dev);
// LCD 打开或关闭显示
void lcd_ac_switch(const driver_ht1621_t* dev, uint8_t state);
// 清除显示(不改变显存，直接清除芯片中的显示数据)
void lcd_ac_clear(const driver_ht1621_t* dev);
// 显存操作：显存下发到 LCD 驱动芯片
void lcd_ac_write(const driver_ht1621_t* dev, lcd_ac_ram_t *ram);
// 显存操作：从 LCD 驱动芯片读取当前显示的数据到显存
void lcd_ac_read(const driver_ht1621_t* dev, lcd_ac_ram_t *ram);
// 显示指定内容
void lcd_ac_set(const driver_ht1621_t* dev, lcd_ac_mode_t mode, lcd_ac_fan_speed_t speed, uint8_t temp_room, uint8_t temp_target);

// 显存操作：清除显存
void lcd_ac_ram_clear(lcd_ac_ram_t *ram);

// 显存操作：设置8段数码显示字符
void lcd_ac_ram_set_char1(lcd_ac_ram_t *ram, lcd_ac_8seg_char_t ch);
void lcd_ac_ram_set_char2(lcd_ac_ram_t *ram, lcd_ac_8seg_char_t ch);
void lcd_ac_ram_set_char3(lcd_ac_ram_t *ram, lcd_ac_8seg_char_t ch);
void lcd_ac_ram_set_char4(lcd_ac_ram_t *ram, lcd_ac_8seg_char_t ch);

// 显存操作：设置基础图形是否显示
void lcd_ac_ram_set_base(lcd_ac_ram_t *ram, uint8_t visible);
// 显存操作：设置室内当前温度显示数值
void lcd_ac_ram_set_temp_room(lcd_ac_ram_t *ram, uint8_t val);
// 显存操作：设置设定温度显示数值
void lcd_ac_ram_set_temp_target(lcd_ac_ram_t *ram, uint8_t val);
// 显存操作：设置风速
void lcd_ac_ram_set_fan_speed(lcd_ac_ram_t *ram, lcd_ac_fan_speed_t speed);
// 显存操作：设置模式
void lcd_ac_ram_set_mode(lcd_ac_ram_t *ram, lcd_ac_mode_t mode);

// 测试
void lcd_ac_test(const driver_ht1621_t* dev);


#endif // _LCD_AC_H_
